/** \file    bsgt.cpp
  * \brief   storable segmentation data, 'b' here stands for brief & binary.
  * \date    2002
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/segm/src/bsgt.cpp,v 1.1 2004/05/20 09:11:46 cscom1r4 Exp $
  */

#include "segm/bsgt.h"

const char * const signature = "bsgt00000000"; //to take with segment counter 16 bytes

void bsgt::testAgainstThresholds(float tIn, float tOut) const
{
	if (weightsEffect & WeightsDepend) {
		bool in_permit = tIn <= wIn;
		bool out_permit = tOut <= wOut;
		if (!(in_permit && out_permit)) {
			if (in_permit) {
				tOn = true;
				return;
			}
			if (out_permit) {
				tOn = false;
				return;
			}
		}
	}
	tOn = 0 != (weightsEffect & HalfCovered);
}

void bsgtt::writeHeader(xtd::bostream &b, xtd::int32u scount)
{
	b.write(signature, strlen(signature));
	b << scount;
}

xtd::bistream & operator >> (xtd::bistream &b, bsgtt &sg)
{
	sg.clear();

	const char *s;
	for (s = signature; *s; ++s) {
		char c;
		b >> c;
		if (c != *s)
			throw bad_signature();
	}

	xtd::int32u scount, i;
	b >> scount;

	bsgt g;
	for (i = 0; i != scount; ++i) {
		b >> g;
		sg.insert(g);
	}

	return b;
}
